package data.vectors.decorator;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;

import data.vectors.DoubleVector;
import data.vectors.DoubleVectorIterator;

public class DoubleVector_SV extends DoubleVector {
	private ArrayList<Integer> index;
	private DoubleVector toDec;
	
	
	
	public DoubleVector_SV(ArrayList<Integer> index, DoubleVector toDec) {
		super();
		this.index = index;
		this.toDec = toDec;
	}
	/**
	 * @return
	 * @see data.vectors.DoubleVector#size()
	 */
	public int size() {
		return index.size();
	}
	/**
	 * @param i
	 * @return
	 * @see data.vectors.DoubleVector#getValue(int)
	 */
	public double getValue(int i) {
		return toDec.getValue(index.get(i));
	}
	/**
	 * @return
	 * @see data.vectors.DoubleVector#getNumberNonNullValues()
	 */
	public int getNumberNonNullValues() {
		return size();
	}
	/**
	 * @return
	 * @see data.vectors.DoubleVector#getIterator()
	 */
	public DoubleVectorIterator getIterator() {
		return new DoubleVectorSVIterator();
	}
	/**
	 * @return
	 * @see data.vectors.DoubleVector#getNonNullIterator()
	 */
	public DoubleVectorIterator getNonNullIterator() {
		return new DoubleVectorSVIterator();
	}
	
	
	
	protected final  class DoubleVectorSVIterator implements DoubleVectorIterator {

		private Iterator<Integer> iterator;
		private int curIndexInOriginal;
		private int curIndexNew;
		
		public DoubleVectorSVIterator()
		{
			this.iterator=index.iterator();	
			curIndexNew = -1;
		}
		
		public final int getCurrentFeature() {
			return curIndexNew;
		}

		public final double getCurrentValue() {
			return(toDec.getValue(curIndexInOriginal));
		}

		public final boolean hasNext() {
			return this.iterator.hasNext();
		}

		public final void next() {
			curIndexInOriginal=iterator.next();
			curIndexNew++;
		}

	}
	
}
